package com.starchen.optimalselection.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starchen.optimalselection.product.model.CategoryBrandRelation;
import com.starchen.optimalselection.product.model.vo.CategoryBrandRelationVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 品牌分类关联
 * 
 * @author daxilong
 * @email daxilong@gmail.com
 * @date 2022-08-14 19:57:36
 */
@Mapper
public interface CategoryBrandRelationMapper extends BaseMapper<CategoryBrandRelation> {

    @Select("SELECT r.id, r.brand_id,r.category_id,c.name cname,b.name bname FROM pms_category_brand_relation r JOIN  pms_category c ON r.category_id = c.id JOIN pms_brand b ON r.brand_id = b.id WHERE r.brand_id = #{brandId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "brandId", column = "brand_id"),
            @Result(property = "categoryId", column = "category_id"),
            @Result(property = "categoryName", column = "cname"),
            @Result(property = "brandName", column = "bname")
    })
    List<CategoryBrandRelationVo> getCategoryBrandRelation(@Param("brandId") Long brandId);

}
